package moerrors

import "fmt"

type ValidateMsgError struct {
	err  error
	Code int
	Msg  string
}

func NewValidateMsgError(code int, msg string, err error) error {
	return &ValidateMsgError{err: err, Code: code, Msg: msg}
}
func NewValidateError(code int, msg string) error {
	return &ValidateMsgError{Code: code, Msg: msg}
}
func New(err error) error {
	return &ValidateMsgError{err: err}
}
func NewWithMsg(msg string) error {
	return &ValidateMsgError{Msg: msg}
}

// ---
func (v *ValidateMsgError) Error() string {
	if v.err == nil {
		return fmt.Sprintf("code:%d,msg:%s", v.Code, v.Msg)
	}
	return fmt.Sprintf("code:%d,msg:%s, err: %+v", v.Code, v.Msg, v.err)
}
func (v *ValidateMsgError) Is(target error) bool {
	_, ok := target.(*ValidateMsgError)
	if !ok {
		return false
	}
	return true
}

func (v *ValidateMsgError) As(target interface{}) bool {
	targetError, ok := target.(*ValidateMsgError)
	if !ok {
		return false
	}
	return v == targetError
}
